package cn.leonis.leetcode;

/**
 * @author Tobi
 * @time 2021-07-10 10:42 AM
 * 查找第一个错误版本号
 * leetcode278
 */
public class FirstBadVersionSolution {

    public static void main(String[] args) {

    }

    /**
     * 使用二分查找，可以尽量减少调用接口
     * @param n
     * @return
     */
    public int firstBadVersion(int n) {
        int pl = 1;
        int pr = n;
        while (pl < pr) {
            int mid = pl + (pr - pl) / 2;
            if (!isBadVersion(mid)) {
                pl = mid + 1;
            }else {
                pr = mid;
            }
        }

        return pl;
    }

    public boolean isBadVersion(int n) {
        return true;
    }
}
